/**
 Created by:
 muhtearjan mehmood مۇختەرجان مەخمۇت (Email: yeganaaa@163.com)
 At 8/19/20 3:11 AM
 */
import {IRpcServerHost, ServerHostEvents} from "../src/Core/RpcServer";
import {IRpcBridgeHost} from "../src/Core/RpBridge";
import {MemoryRpcBridgeHost} from "./MemoryRpcBridgeHost";

export class MemoryRpcServerHost implements IRpcServerHost<void> {
    backend: void = null!
    private eventHandler: ServerHostEvents = null!;

    public async launch(): Promise<void> {
        await this.eventHandler.onReady()
    }

    public async prepare(eventHandler: ServerHostEvents): Promise<void> {
        this.eventHandler = eventHandler
    }

    public async shutdown(): Promise<void> {
        await this.eventHandler.onShutdown()
    }

    public connect(rpcBridgeHost: MemoryRpcBridgeHost) {
        const bridge = rpcBridgeHost.createLinkedBridge()
        // bridge.isOpen = true
        this.eventHandler.onClientConnected(bridge)
    }
}

